package softstarter.gui.reborn;

import java.awt.Color;
import java.awt.GradientPaint;
import java.awt.Graphics;
import java.awt.Graphics2D;

import javax.swing.JPanel;

public class GradientPanel extends JPanel {
	
	public enum GradienceDirection {
		HORIZONTAL,
		VERTICAL
	};
	
	private Color gradientColorStart;
	private Color gradientColorEnd;
	private GradienceDirection gd;
	
	private boolean colorsModified;
	
	public GradientPanel() {
		super();
		this.gd = GradienceDirection.HORIZONTAL;
		colorsModified = false;
	}
	
	public GradientPanel(Color gradientColorStart, Color gradientColorEnd) {
		this();
		setColors(gradientColorStart,gradientColorEnd);
	}
	
	public void setColors(Color gradientColorStart, Color gradientColorEnd) {
		this.gradientColorStart = gradientColorStart;
		this.gradientColorEnd = gradientColorEnd;
		colorsModified = true;
	}
	
	public void setGradienceDirection(GradienceDirection direction) {
		this.gd = direction;
	}
	
	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		Graphics2D g2 = (Graphics2D)g;
		
		if (! colorsModified) {
			gradientColorStart =  this.getBackground().brighter();
			gradientColorEnd = this.getBackground();
		}
		
		
		int x1 = 0; // x1 0, y1 -10, x2 0, y2 30
		int y1 = 0;
		int x2 = 0;
		int y2 = 0;
		
		if (gd == GradienceDirection.HORIZONTAL) {
			x1 = 0;
			y1 = -10;
			x2 = 0;
			y2 = 15;
			
			if (colorsModified) y2 = 15;
			
		}
		else if (gd == GradienceDirection.VERTICAL) {
			x1 = 0;
			y1 = 0;
			x2 = 10; // 30
			y2 = 0;
		}
		
		GradientPaint gp = new GradientPaint(x1, y1, gradientColorStart, 
				 x2, y2, gradientColorEnd, false);
		g2.setPaint(gp);
		
		g2.fillRect(0, 0, this.getWidth(), this.getHeight());
		

	}

}
